﻿using System;
using System.Collections.Generic;
using System.Configuration;
using CoreLab.MySql;
using NENAData.Errors;
using NENAData.LINQ;
using System.Text;

namespace NENAData.MYSQL
{
    public class MYSQLMember
    {
        //public int Get_PNUID(string strUsername)
        //{

        //    string strSQL = "select pn_uid from nena_users where pn_uname = @UName ";
        //    Int32 intOutput;

        //    MySqlConnection MySqlCon = new MySqlConnection(ConfigurationManager.AppSettings["MYSQLConnectionString"]);
        //    MySqlCommand MySqlCom = new MySqlCommand(strSQL, MySqlCon);

        //    MySqlCom.Parameters.Add("@UName", strUsername);

        //    MySqlCon.Open();
        //    //var varoutput = (Int32)MySqlCom.ExecuteScalar();
        //    try
        //    {
        //        intOutput = (Int32)MySqlCom.ExecuteScalar();
        //    }
        //    catch
        //    {
        //        //member does not exist
        //        intOutput = 0;
        //    }
        //    MySqlCon.Close();

        //    return intOutput;
        //}

        //public void UpdateMemberStatus(int intMemberID, int intStatus)
        //{
        //    try
        //    {

        //    string strSQL = "update nena_users set pn_uactive = @Status where pn_uid = @UID ";

        //    MySqlConnection MySqlCon = new MySqlConnection(ConfigurationManager.AppSettings["MYSQLConnectionString"]);
        //    MySqlCommand MySqlCom = new MySqlCommand(strSQL, MySqlCon);

        //    MySqlCom.Parameters.Add("@UID", intMemberID);
        //    MySqlCom.Parameters.Add("@Status", intStatus);

        //    MySqlCon.Open();
        //    MySqlCom.ExecuteNonQuery();
        //    MySqlCon.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        ErrHandler.WriteError(ex.Message);
        //        throw (ex);
        //    }
        //}

        //public string Insert(Member pMember, int intStatus)
        //{
        //    try
        //    {

        //        StringBuilder strBuilder = new StringBuilder();

        //        //pn_name, pn_uname, pn_user_regdate, pn_user_from, pn_email, pn_pass, pn_uactive, pn_ulevel
        //        strBuilder.Append(
        //            "insert into nena_users  (pn_name, pn_uname,  pn_email, pn_pass, pn_uactive, pn_ulevel,");
        //        strBuilder.Append("pn_user_from, pn_user_regdate) values ");
        //        strBuilder.Append("( @PNName, @PNUname, @PNEmail, md5(@PNPass), @PNActive, @PNLevel,");
        //        strBuilder.Append("@PNFrom, now());");

        //        //set pn_uactive = @Status where pn_uid = @UID ");
        //        string strpassword = NENAMember.Account.Password.Generate(6);

        //        MySqlConnection MySqlCon = new MySqlConnection(ConfigurationManager.AppSettings["MYSQLConnectionString"]);
        //        MySqlCommand MySqlCom = new MySqlCommand(strBuilder.ToString(), MySqlCon);

        //        string strAccountName = pMember.LastName + pMember.FirstName;
        //        strAccountName = strAccountName.Replace(" ", "");

        //        MySqlCom.Parameters.Add("@PNName", pMember.FirstName + " " + pMember.LastName);
        //        MySqlCom.Parameters.Add("@PNUname", strAccountName);
        //        MySqlCom.Parameters.Add("@PNEmail", pMember.EmailAddress);
        //        MySqlCom.Parameters.Add("@PNPass", strpassword);
        //        MySqlCom.Parameters.Add("@PNActive", intStatus);
        //        MySqlCom.Parameters.Add("@PNLevel", "0");
        //        MySqlCom.Parameters.Add("@PNFrom", pMember.City + ", " + pMember.Province + ", " + pMember.Country);

        //        MySqlCon.Open();
        //        MySqlCom.ExecuteNonQuery();
        //        MySqlCon.Close();

        //        return strpassword;

        //    }
        //    catch (Exception ex)
        //    {
        //        ErrHandler.WriteError(ex.Message);
        //        throw (ex);
        //    }
        //}
    }
}
